﻿using MediatR;
using Traceability.Commont.Domains.AnimalsDomainFiles;
using Traceability.Commont.Domains.ScratchTheFat;
using Traceability.Commont.DTOs.CommontFiles;
using Traceability.Commont.DTOs.WhiteStripWeighingHtmlGroup;
using Traceability.Commont.Infrastructures.Interfaces;

namespace U.Enterprise.Api.Applications.SplitDetails
{
    public class SaleDetailsHander : IRequestHandler<SaleDetailsCommand, Resqults<SalesDetailsDTO>>
    {
        private readonly IBateRepository<SalesWeighing> sale;
        private readonly IBateRepository<Shopping> shop;
        private readonly IBateRepository<Scale> scale;

        public SaleDetailsHander(IBateRepository<SalesWeighing> sale, IBateRepository<Shopping> shop, IBateRepository<Scale> scale)
        {
            this.sale = sale;
            this.shop = shop;
            this.scale = scale;
        }

        public async Task<Resqults<SalesDetailsDTO>> Handle(SaleDetailsCommand request, CancellationToken cancellationToken)
        {
            try
            {
                Resqults<SalesDetailsDTO> res = new Resqults<SalesDetailsDTO>();
                var list = from a in sale.GetAll()
                           join b in shop.GetAll() on a.ProductCode equals b.ShoppingDesignationid
                           join c in scale.GetAll() on a.ScaleId equals c.Scaleid
                           select new SalesDetailsDTO()
                           {
                               ProductCode = b.ShoppingDesignationName,
                               WeightNum = a.WeightNum,
                               NetWeight = a.NetWeight,
                               ScaleId = c.ScaleName,
                               WeigheTime = a.WeigheTime,
                               ClientID = a.ClientID
                           };
                res.Date = list.ToList();
                return res;
            }
            catch (Exception)
            {

                throw;
            }
        }
    }
}
